
package com.jz.community.moduleshopping.confirmOrder.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.bean.baseGoods.GoodInfo;
import com.jz.community.basecomm.constant.AppConstants;
import com.jz.community.basecomm.glideConfig.GlideApp;
import com.jz.community.basecomm.utils.CharacterUtils;
import com.jz.community.basecomm.utils.ConverterUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.basecomm.utils.RxTextTool;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshopping.R;

import java.util.List;

public class ConfirmGoodsListItemAdapter extends BaseQuickAdapter<GoodInfo, BaseViewHolder> {
    public ConfirmGoodsListItemAdapter(int layoutResId, @Nullable List<GoodInfo> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodInfo item) {
        ImageView iv_shop_goods_photo = helper.getView(R.id.iv_shop_goods_photo);
        TextView tvShopGoodsDisPriceTv = helper.getView(R.id.tv_shop_goods_disPrice_tv);
        GlideApp.with(mContext)
                .load(item.getImg())
                .placeholder(R.mipmap.image_default)
                .error(R.mipmap.image_default)
                .into(iv_shop_goods_photo);

        helper.setText(R.id.tv_shop_goods_name, item.getName());
        if (item.getBuyType() != 4) {
            if (!Preconditions.isNullOrEmpty(item.getDisCountPrice())) {
                helper.setText(R.id.tv_shop_goods_price, AppConstants.MONEY + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getDisCountPrice())));
                RxTextTool.getBuilder("").append(AppConstants.MONEY + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getPrice()))).setStrikethrough().into(tvShopGoodsDisPriceTv);
                SHelper.vis(tvShopGoodsDisPriceTv);
            } else {
                SHelper.gone(tvShopGoodsDisPriceTv);
                helper.setText(R.id.tv_shop_goods_price, AppConstants.MONEY + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getPrice())));
            }
        } else {
            if (!Preconditions.isNullOrEmpty(item.getDisCountPrice())) {
                helper.setText(R.id.tv_shop_goods_price, AppConstants.MONEY + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getDisCountPrice() + "积分")));
                RxTextTool.getBuilder("").append(AppConstants.MONEY + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getPrice()))).setStrikethrough().into(tvShopGoodsDisPriceTv);
                SHelper.vis(tvShopGoodsDisPriceTv);
            } else {
                SHelper.gone(tvShopGoodsDisPriceTv);
                helper.setText(R.id.tv_shop_goods_price, AppConstants.MONEY + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getPrice() + "积分")));
            }
        }
        helper.setText(R.id.tv_shop_goods_description, item.getSkuName());
        helper.setText(R.id.tv_shop_goods_buy_count, "x" + String.valueOf(item.getNums()));
    }
}

